require(['config'], function () {
    require(['jquery'], function () {
        (function () {
            const username = $('.reg-wrap .regForm .bg .log-input .l-input1');
            const password = $('.reg-wrap .regForm .bg .log-input .l-input2');
            const form1 = $('.reg-wrap .regForm');
            const uspan = $('.reg-wrap .uspan');
            const pspan = $('.reg-wrap .pspan');
            console.log(username);
            username.blur(function () {
                let phpurl = 'http://10.31.155.19/MallProject/php/';
                $.ajax({
                    type: 'POST',
                    url: phpurl + 'registry.php',
                    datatype: 'json',
                    data: { name: username.val() }
                }).done(function (registrydata) {
                    console.log(registrydata);
                    let reg1 = /^1[3578]\d{9}$/;
                    let reg2 = /\w{6}/;
                        if (!registrydata && reg1.test(username.val())) {
                            uspan.html('电话有效');
                            uspan.css({color:"green"});
                            repeatlock = true;
                            console.log(1);
                        } else if(!reg1.test(username.val())){
                            console.log(!reg.test(username.val()))
                            uspan.html('请输入正确的手机号');
                            uspan.css({color:'red'});
                            repeatlock = false;
                            console.log(repeatlock);
                            console.log(2);
                        }else {
                            uspan.html('该电话已被注册');
                            uspan.css({color:'red'});
                            repeatlock = false;
                            console.log(3);
                        }
                    
                    password.blur(function(){
                        if(reg2.test(password.val())){
                            pspan.html('密码有效');
                            pspan.css({color:'green'}); 
                            repeatlock = true; 
                        }else{
                            pspan.html('密码长度错误');
                            pspan.css({color:'red'});
                            repeatlock = false;
                        }
                    });
                    
                });
                form1.submit(function(){
                    if(!repeatlock){
                        return false;
                    }else{
                        alert('注册成功');
                    }
                });
            });
        })()
    });
});